package com.zpp.wedding_admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zpp.wedding_admin.entity.Collect;
import com.zpp.wedding_admin.entity.Good;
import com.zpp.wedding_admin.service.ICollectService;
import com.zpp.wedding_admin.utils.LQWUtils;
import com.zpp.wedding_common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "收藏管理")
@CrossOrigin
@RestController
@RequestMapping("/weddingadmin/collect")
public class CollectController {

    @Autowired
    private ICollectService collectService;

    @GetMapping("getCollect/{id}")
    public R getCollect(@PathVariable String id) {
        List<Collect> collectList = collectService.getCollect(id);
        return R.ok().data("collectList", collectList);
    }

    @ApiOperation(value = "是否收藏当前文章")
    @GetMapping("isCollectWork/{id}/{userId}")
    public R isCollectWork(@PathVariable Integer id, @PathVariable Integer userId) {
        LambdaQueryWrapper<Collect> lqw = LQWUtils.getLqw(Collect.class);
        lqw.eq(Collect::getUserId, userId).eq(Collect::getWorkId, id);
        Collect collect = collectService.getOne(lqw);
        if ( collect != null ) {
            return R.ok().data("isCollect", true);
        } else {
            return R.ok().data("isCollect", false);
        }
    }

}
